#ifndef __SEM_H__
#define __SEM_H__

#include <types.h>
#include <list.h>
#include <queue.h>

#include <sys/event.h>
#include <sys/task.h>
#include <sys/thread.h>
#include <sys/unistd.h>

struct sem {
    struct sem *next;
    list_t task_link;		/* link in task list */

    task_t *owner;
    event_t evt;		/* waiting queue of tasks */

    int ref_cnt;		/* refrences counter */
    uint32_t value;
};

int sem_init(sem_t **, uint32_t);
int sem_destroy(sem_t **);
int sem_wait(sem_t **, uint32_t);
int sem_trywait(sem_t **);
int sem_post(sem_t **);
void sem_cleanup(task_t *);
int sem_getval(sem_t **, uint32_t *);

#endif	/* __SEM_H__ */
